Public Class frmEditFactions
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents pnlFactionOneProperties As System.Windows.Forms.Panel
    Friend WithEvents txtFactionOneName As System.Windows.Forms.TextBox
    Friend WithEvents txtFactionOneDescription As System.Windows.Forms.TextBox
    Friend WithEvents txtFactionOnePoints As System.Windows.Forms.TextBox
    Friend WithEvents lblFactionOneName As System.Windows.Forms.Label
    Friend WithEvents lblFactionOnePoints As System.Windows.Forms.Label
    Friend WithEvents lblFactionOneDescription As System.Windows.Forms.Label
    Friend WithEvents Panel1 As System.Windows.Forms.Panel
    Friend WithEvents lblFactionTwoDescription As System.Windows.Forms.Label
    Friend WithEvents lblFactionTwoPoints As System.Windows.Forms.Label
    Friend WithEvents lblFactionTwoName As System.Windows.Forms.Label
    Friend WithEvents txtFactionTwoPoints As System.Windows.Forms.TextBox
    Friend WithEvents txtFactionTwoDescription As System.Windows.Forms.TextBox
    Friend WithEvents txtFactionTwoName As System.Windows.Forms.TextBox
    Friend WithEvents btnOK As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(frmEditFactions))
        Me.pnlFactionOneProperties = New System.Windows.Forms.Panel()
        Me.lblFactionOneDescription = New System.Windows.Forms.Label()
        Me.lblFactionOnePoints = New System.Windows.Forms.Label()
        Me.lblFactionOneName = New System.Windows.Forms.Label()
        Me.txtFactionOnePoints = New System.Windows.Forms.TextBox()
        Me.txtFactionOneDescription = New System.Windows.Forms.TextBox()
        Me.txtFactionOneName = New System.Windows.Forms.TextBox()
        Me.Panel1 = New System.Windows.Forms.Panel()
        Me.lblFactionTwoDescription = New System.Windows.Forms.Label()
        Me.lblFactionTwoPoints = New System.Windows.Forms.Label()
        Me.lblFactionTwoName = New System.Windows.Forms.Label()
        Me.txtFactionTwoPoints = New System.Windows.Forms.TextBox()
        Me.txtFactionTwoDescription = New System.Windows.Forms.TextBox()
        Me.txtFactionTwoName = New System.Windows.Forms.TextBox()
        Me.btnOK = New System.Windows.Forms.Button()
        Me.pnlFactionOneProperties.SuspendLayout()
        Me.Panel1.SuspendLayout()
        Me.SuspendLayout()
        '
        'pnlFactionOneProperties
        '
        Me.pnlFactionOneProperties.BackColor = System.Drawing.SystemColors.ControlLight
        Me.pnlFactionOneProperties.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.pnlFactionOneProperties.Controls.AddRange(New System.Windows.Forms.Control() {Me.lblFactionOneDescription, Me.lblFactionOnePoints, Me.lblFactionOneName, Me.txtFactionOnePoints, Me.txtFactionOneDescription, Me.txtFactionOneName})
        Me.pnlFactionOneProperties.Location = New System.Drawing.Point(8, 8)
        Me.pnlFactionOneProperties.Name = "pnlFactionOneProperties"
        Me.pnlFactionOneProperties.Size = New System.Drawing.Size(248, 256)
        Me.pnlFactionOneProperties.TabIndex = 2
        '
        'lblFactionOneDescription
        '
        Me.lblFactionOneDescription.Location = New System.Drawing.Point(16, 112)
        Me.lblFactionOneDescription.Name = "lblFactionOneDescription"
        Me.lblFactionOneDescription.Size = New System.Drawing.Size(168, 24)
        Me.lblFactionOneDescription.TabIndex = 5
        Me.lblFactionOneDescription.Text = "Description"
        '
        'lblFactionOnePoints
        '
        Me.lblFactionOnePoints.Location = New System.Drawing.Point(16, 74)
        Me.lblFactionOnePoints.Name = "lblFactionOnePoints"
        Me.lblFactionOnePoints.Size = New System.Drawing.Size(80, 24)
        Me.lblFactionOnePoints.TabIndex = 4
        Me.lblFactionOnePoints.Text = "Point Value"
        '
        'lblFactionOneName
        '
        Me.lblFactionOneName.Location = New System.Drawing.Point(16, 8)
        Me.lblFactionOneName.Name = "lblFactionOneName"
        Me.lblFactionOneName.Size = New System.Drawing.Size(168, 24)
        Me.lblFactionOneName.TabIndex = 3
        Me.lblFactionOneName.Text = "Side One Faction Name"
        '
        'txtFactionOnePoints
        '
        Me.txtFactionOnePoints.Location = New System.Drawing.Point(96, 72)
        Me.txtFactionOnePoints.Name = "txtFactionOnePoints"
        Me.txtFactionOnePoints.Size = New System.Drawing.Size(136, 20)
        Me.txtFactionOnePoints.TabIndex = 1
        Me.txtFactionOnePoints.Text = "0"
        Me.txtFactionOnePoints.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
        '
        'txtFactionOneDescription
        '
        Me.txtFactionOneDescription.Location = New System.Drawing.Point(16, 144)
        Me.txtFactionOneDescription.Multiline = True
        Me.txtFactionOneDescription.Name = "txtFactionOneDescription"
        Me.txtFactionOneDescription.ScrollBars = System.Windows.Forms.ScrollBars.Vertical
        Me.txtFactionOneDescription.Size = New System.Drawing.Size(216, 104)
        Me.txtFactionOneDescription.TabIndex = 2
        Me.txtFactionOneDescription.Text = "Side One"
        '
        'txtFactionOneName
        '
        Me.txtFactionOneName.Location = New System.Drawing.Point(16, 32)
        Me.txtFactionOneName.Name = "txtFactionOneName"
        Me.txtFactionOneName.Size = New System.Drawing.Size(216, 20)
        Me.txtFactionOneName.TabIndex = 0
        Me.txtFactionOneName.Text = "Side One"
        '
        'Panel1
        '
        Me.Panel1.BackColor = System.Drawing.SystemColors.ControlLight
        Me.Panel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.Panel1.Controls.AddRange(New System.Windows.Forms.Control() {Me.lblFactionTwoDescription, Me.lblFactionTwoPoints, Me.lblFactionTwoName, Me.txtFactionTwoPoints, Me.txtFactionTwoDescription, Me.txtFactionTwoName})
        Me.Panel1.Location = New System.Drawing.Point(264, 8)
        Me.Panel1.Name = "Panel1"
        Me.Panel1.Size = New System.Drawing.Size(248, 256)
        Me.Panel1.TabIndex = 3
        '
        'lblFactionTwoDescription
        '
        Me.lblFactionTwoDescription.Location = New System.Drawing.Point(16, 112)
        Me.lblFactionTwoDescription.Name = "lblFactionTwoDescription"
        Me.lblFactionTwoDescription.Size = New System.Drawing.Size(168, 24)
        Me.lblFactionTwoDescription.TabIndex = 5
        Me.lblFactionTwoDescription.Text = "Description"
        '
        'lblFactionTwoPoints
        '
        Me.lblFactionTwoPoints.Location = New System.Drawing.Point(16, 74)
        Me.lblFactionTwoPoints.Name = "lblFactionTwoPoints"
        Me.lblFactionTwoPoints.Size = New System.Drawing.Size(80, 24)
        Me.lblFactionTwoPoints.TabIndex = 4
        Me.lblFactionTwoPoints.Text = "Point Value"
        '
        'lblFactionTwoName
        '
        Me.lblFactionTwoName.Location = New System.Drawing.Point(16, 8)
        Me.lblFactionTwoName.Name = "lblFactionTwoName"
        Me.lblFactionTwoName.Size = New System.Drawing.Size(168, 24)
        Me.lblFactionTwoName.TabIndex = 3
        Me.lblFactionTwoName.Text = "Side Two Faction Name"
        '
        'txtFactionTwoPoints
        '
        Me.txtFactionTwoPoints.Location = New System.Drawing.Point(96, 72)
        Me.txtFactionTwoPoints.Name = "txtFactionTwoPoints"
        Me.txtFactionTwoPoints.Size = New System.Drawing.Size(136, 20)
        Me.txtFactionTwoPoints.TabIndex = 4
        Me.txtFactionTwoPoints.Text = "0"
        Me.txtFactionTwoPoints.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
        '
        'txtFactionTwoDescription
        '
        Me.txtFactionTwoDescription.Location = New System.Drawing.Point(16, 144)
        Me.txtFactionTwoDescription.Multiline = True
        Me.txtFactionTwoDescription.Name = "txtFactionTwoDescription"
        Me.txtFactionTwoDescription.ScrollBars = System.Windows.Forms.ScrollBars.Vertical
        Me.txtFactionTwoDescription.Size = New System.Drawing.Size(216, 104)
        Me.txtFactionTwoDescription.TabIndex = 5
        Me.txtFactionTwoDescription.Text = "Side Two"
        '
        'txtFactionTwoName
        '
        Me.txtFactionTwoName.Location = New System.Drawing.Point(16, 32)
        Me.txtFactionTwoName.Name = "txtFactionTwoName"
        Me.txtFactionTwoName.Size = New System.Drawing.Size(216, 20)
        Me.txtFactionTwoName.TabIndex = 3
        Me.txtFactionTwoName.Text = "Side Two"
        '
        'btnOK
        '
        Me.btnOK.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnOK.Location = New System.Drawing.Point(432, 272)
        Me.btnOK.Name = "btnOK"
        Me.btnOK.TabIndex = 6
        Me.btnOK.Text = "OK"
        '
        'frmEditFactions
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(518, 300)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.btnOK, Me.Panel1, Me.pnlFactionOneProperties})
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow
        Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
        Me.Name = "frmEditFactions"
        Me.ShowInTaskbar = False
        Me.Text = "Edit Factions"
        Me.pnlFactionOneProperties.ResumeLayout(False)
        Me.Panel1.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private ptrFactions As cmplib01.Factions
    Private ptrFactOne As cmplib01.Faction
    Private ptrFactTwo As cmplib01.Faction

    Public Sub New(ByRef facts As cmplib01.Factions)
        ' in the current version, there are two factions, 1 and two that are automatically created. We'll use the first
        ' two factions found until an update comes in the future... maybe.
        Me.New()
        ptrFactions = facts

        Dim de As DictionaryEntry
        Dim sKey As String
        Dim i As Int16

        For Each de In ptrFactions.HT
            sKey = de.Key.ToString
            If i = 0 Then
                ptrFactOne = ptrFactions.HT.Item(sKey)
                i = 1
            Else
                ptrFactTwo = ptrFactions.HT.Item(sKey)
                Exit For
            End If
        Next

        PopulateProperties()

    End Sub

    Private Sub PopulateProperties()
        txtFactionOneName.Text = ptrFactOne.FactionName
        txtFactionOnePoints.Text = ptrFactOne.FactionTotalPoints.ToString
        txtFactionOneDescription.Text = ptrFactOne.FactionDescription

        txtFactionTwoName.Text = ptrFactTwo.FactionName
        txtFactionTwoPoints.Text = ptrFactTwo.FactionTotalPoints.ToString
        txtFactionTwoDescription.Text = ptrFactTwo.FactionDescription
    End Sub

    Private Function SaveProperties() As Boolean
        Dim res As Boolean = True

        Try
            If txtFactionOneName.Text = "" Then
                Dim ex As Exception
                Throw ex
            End If
            ptrFactOne.FactionName = txtFactionOneName.Text
        Catch
            res = False
            ptrFactOne.FactionName = "Side One"
        End Try

        Try
            ptrFactOne.FactionTotalPoints = CType(txtFactionOnePoints.Text, Int16)
        Catch
            ptrFactOne.FactionTotalPoints = 0
            txtFactionOnePoints.Text = "0"
            res = False
        End Try

        Try
            ptrFactOne.FactionDescription = txtFactionOneDescription.Text
        Catch
            ptrFactOne.FactionDescription = "Side One"
            res = False
        End Try

        Try
            If txtFactionTwoName.Text = "" Then
                Dim ex As Exception
                Throw ex
            End If
            ptrFactTwo.FactionName = txtFactionTwoName.Text
        Catch
            res = False
            ptrFactTwo.FactionName = "Side Two"
        End Try

        Try
            ptrFactTwo.FactionTotalPoints = CType(txtFactionTwoPoints.Text, Int16)
        Catch
            ptrFactTwo.FactionTotalPoints = 0
            txtFactionTwoPoints.Text = "0"
            res = False
        End Try

        Try
            ptrFactTwo.FactionDescription = txtFactionTwoDescription.Text
        Catch
            ptrFactTwo.FactionDescription = "Side Two"
            res = False
        End Try

        Return res
    End Function

    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
        If SaveProperties() = True Then
            Me.Hide()
        Else
            MsgBox("Some data is incorrect. Make sure all fields have appropriate data.", MsgBoxStyle.Exclamation, "Invalid Property")
        End If
    End Sub

End Class
